package com.wc5818.utils;

import com.qiniu.common.Zone;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;



/**
 * @author zaizai
 * @date 2020/2/19 14:00
 * @Description
 **/
public class QiniuCloudUtil {
    //七牛云的AK和SK
    private static final String ACCESS_KEY="ke7MrFXqZnJ3BxbOkGnPogJBvIhDT2-69qYaxumQ";
    private static final String SECRET_KEY="goHqzY5hF5o9RwGH2qtVYMeHBFweZyRvDsCDrhFj";
    //要上传的存储空间名
    private static final String BUCKET="wc-wx-img";
    //外链地址
    private static final String DOMAIN="img.wc5818.com";
    private static final Auth auth = Auth.create(ACCESS_KEY,SECRET_KEY);
    /**
     * 获取七牛云Token
     * @return
     */
    public static String getupToken(){

        StringMap stringMap = new StringMap();
        //上传成功后返回
        stringMap.put("returnBody","{\"fileUrl\":\""+DOMAIN+"${key}\"}");
        //过期时间
        long expireSeconds = 3600;
        String upToken = auth.uploadToken(BUCKET, null, expireSeconds, stringMap);
        System.out.println(upToken);
        return upToken;
    }
//    public static String uploadFile(){
//        //文件的外链地址
//        StringBuffer fileUrl = new StringBuffer(DOMAIN);
//        //构造一个带指定Zone对象的配置类
//        Configuration cfg = new Configuration(Zone.zone2());
//        UploadManager uploadManager = new UploadManager(cfg);
//
//    }

}
